<?php

defined('SYSPATH') or die('Access error!');

class Controller_Goods extends Controller_Shop_Main
{

    private $goods;

    public function before()
    {
        parent::before();
        $this->goods = Model::factory('shop_goods');
        I18n::set_current_file('shop');
    }

    //获取某个产品
    public function action_index()
    {
        $goods_id = intval($this->request->param('id'));

        if (empty($goods_id) || !$this->goods->is_exist(array('id' => $goods_id)))
        {
            $this->request->redirect(URL::site('shop'));
        }
        $goods_detail = $this->goods->get_goods_detail($goods_id);
        $this->set_goods_category_position($goods_detail['category_id']);
        Statics::instance()->update_static('shop_goods_static', array('goods_id' => $goods_id), 'views');
        $this->detail_seo($goods_id, $goods_detail['name'], $goods_detail['content']);
        $this->template->assign('data', $goods_detail);
        $this->template->assign('goods_order_list',Model::factory('shop_order')->get_goods_order($goods_id));
        $this->template->assign('goods_comments_list',$this->goods->get_goods_comments($goods_id));
        $this->template->view('shop_goods_detail');
    }

    //获取产品的列表
    public function action_list()
    {

        $id = intval($this->request->param('id')) == 0 ? SHOP_CATEGORY_ID : intval($this->request->param('id'));
         $this->set_seo($this->category_seo($id));
        $this->set_goods_category_position($id);
        $goods_list = Model::factory('shop_goods')->get_list_by_category_id($id);
        $this->template->assign('goods_list', $goods_list['list']);
        $this->template->assign('page', $goods_list['page']);
        $this->template->view('shop_goods_list');
    }

}